package com.huli.controller;

import com.huli.pojo.SysMaterial;
import com.huli.pojo.SysOrganization;
import com.huli.service.MaterialService;
import com.huli.util.Result;
import com.huli.vo.OrganizationUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/material")
public class MaterialController {
    @Autowired
    private MaterialService materialService;

    @RequestMapping("/materialList")
    public List<SysMaterial> materialList(){
        return materialService.materialList();
    }

    // 分页查询耗材表
    @RequestMapping("/materialList1")
    public Result materialList1(OrganizationUserVo param){
        OrganizationUserVo organizationUserVo = materialService.materialList1(param);
        return Result.success(organizationUserVo);
    }

    // 删除耗材表
    @RequestMapping("/deleteMaterial")
    public Result deleteMaterial(Long id){
        try {
            materialService.deleteMaterial(id);
            return Result.success("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("删除失败");
        }
    }

    // 修改耗材表
    @RequestMapping("/updateMaterial")
    public Result updateMaterial(SysMaterial sysMaterial){
        try {
            materialService.updateMaterial(sysMaterial);
            return Result.success("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("修改失败");
        }
    }

    // 添加耗材表数据
    @RequestMapping("/addMaterial")
    public Result addMaterial(SysMaterial sysMaterial){
        try {
            materialService.addMaterial(sysMaterial);
            return Result.success("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("添加失败");
        }
    }
    @RequestMapping("/selectMaterialById")
    public Result selectMaterialById(Long id){
        SysMaterial sysMaterial = materialService.selectMaterialById(id);
        return Result.success(sysMaterial);
    }
    @RequestMapping("/materialByMaterialName")
    public List<SysMaterial> materialByMaterialName(String materialName){
        List<SysMaterial> sysMaterial = materialService.materialByMaterialName(materialName);
        return sysMaterial;
    }
    @RequestMapping("/findAll")
    public Result findAll(){
        List<SysMaterial> sysMaterial = materialService.findAll();
        return Result.success(sysMaterial);
    }
}
